<?php
/**
 * Created by PhpStorm.
 * User: weixiong
 * Date: 2017/11/10
 * Time: 15:32
 */
    $c = send_http("http://59.110.156.254:15672/ip/status");
    $log_path = "/home/zyyt/log/nginx/check_nginx.log";

    if( empty($c) || $c['http_code'] != 200 ) {
        echo date("Y-m-d H:i:s") . " | restart php and Nginx ! \n";
        $msg = date("Y-m-d H:i:s") . " | restart php and Nginx ! \n";
        error_log($msg, 3, $log_path);
        exec('/home/zyyt/restart_nginx.sh');
    }else{
        echo date("Y-m-d H:i:s") . " | 服务正常! \n";
    }

    function send_http($url, $post = array()) {

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
            curl_setopt($ch, CURLOPT_TIMEOUT, 15);

            $rs = curl_exec($ch);
            $http_info = curl_getinfo($ch);

            curl_close($ch);
            return $http_info;
    }

?>